<template>
	<view>
		<view class="uni-padding-wrap uni-common-mt" style="padding-left: 0px; padding-right: 0px;">
			<view class="uni-flex uni-column">
				
				<!-- 顶部商品模块 -->
				<view class="bgimage">
				
					<view class="shop-top">
							<view class="shop-con"
								v-for="(item,index1) in listt"
								:key="index1"
								v-if="index1 <=2 "
								@tap="goDetails(item.id)"
							>
								<image class="shop-pic" :src="item.image" mode=""></image>
								<view class="shop-text">{{item.title}}</view>
								<view class="shop-pri">￥{{item.price}}</view>
							</view>
									
					</view>
				</view>
				
				
				<view class="shopback">
					
					<view class="list-title">
						<view
							v-for="(item,index1) in items" 
							:key='index1' 
							class="type" 
							@tap="chooseHead(index1)" 
							:class="headIndex == index1 ?'active':''"
							>{{item}}</view>
						
					</view>
					
					<swiper class="swiper" style="height: 100%;" @change='scollSwiper' :current='headIndex'>
						<swiper-item v-for="(item,index) in items" :key='index'>
							<scroll-view>
								
							</scroll-view>
						</swiper-item>
					</swiper>
				
					
					<view class="box"
						v-for="(item,index1) in list" 
						:key='index1' 
						v-if="item.source == 1&& level > 0 || item.source == 2|| item.source == 0">
						<view class="goods-con">
							<image class="goods-pic" :src="item.image" mode=""></image>
							<view class="goods-info">
								<view class="goods1">{{item.title}}
								</view>
								<text class="goods2">{{item.content}}
								</text>
								<view class="goods3">
									<view class="goods-money">￥{{item.price}}</view>
									<view class="goods-buy" @tap="goDetails(item.id)">立即购买</view>
								</view>
							</view>
						</view>
					</view>
					
				</view>
				
				
			</view>
		</view>
	</view>
</template>

<script>
	// import HotList from '@/components/common/HotList.vue'
	// import CommodityList from '@/components/common/CommodityList.vue'
	// import Hot from '@/components/index/Hot.vue'
	let App = getApp();
	export default {
		data() {
			return {
				items: [],
				type:[],
				headIndex:0,
				list:[],
				level:0,
				listt:[],
			}
		},
		// components:{
		// 	CommodityList,
		// 	HotList
			
		// },
		onShow() {
			this.getGoodsType();
			this.getGoodsTypetop();
		},
		onLoad() {
			
		},
		methods: {
			goDetails(id){
				uni.navigateTo({
					// url:("/pages/shop/details/details")
					url:`/pages/shop/details/details?id=${id}`
				})
			},
			chooseHead(index){
				// uni.pageScrollTo({
				//     scrollTop: 0,
				//     duration: 100,
				// });
				this.headIndex = index
				// this.page = 1
				let userinfo = uni.getStorageSync('userinfo');
			},
			//获取商品分类
			getGoodsType(){
				let userinfo = uni.getStorageSync('userinfo');
				this.$api.interfaceApi('getGoodsType')({
					id:userinfo.id,
					admin:App.globalData.sys
				}).then(res=>{
					if(res.code == 200){
						this.items = res.data.names
						this.type = res.data.type
						this.level = res.data.level
						this.getGoods(this.type[0]['id']);
						// console.log(this.items)
						
					}
				})
			},
			//获取商品列表
			getGoods(type){
				let userinfo = uni.getStorageSync('userinfo');
				uni.showLoading({
					title:"加载中"
				})
				this.$api.interfaceApi('getGoods')({
					admin:App.globalData.sys,
					type:type
				}).then(res=>{
					if(res.code == 200){
						this.list = res.data
						// console.log(this.list)//获取几个属类下的商品
						// console.log(this.type)//获取几个商品分类
						// console.log(res)//获取所有
					}
					uni.hideLoading()
				})
			},
			//获取商品分类
			getGoodsTypetop(){
				let userinfo = uni.getStorageSync('userinfo');
				this.$api.interfaceApi('getGoodsType')({
					id:userinfo.id,
					admin:App.globalData.sys
				}).then(res=>{
					if(res.code == 200){
						this.items = res.data.names
						this.type = res.data.type
						this.level = res.data.level
						this.getGoodstop(this.type[0][1]);
						// console.log(this.items)
						
					}
				})
			},
			//获取顶部商品
			getGoodstop(type){
				let userinfo = uni.getStorageSync('userinfo');
				uni.showLoading({
					title:"加载中"
				})
				this.$api.interfaceApi('getGoods')({
					admin:App.globalData.sys,
					type:1
				}).then(res=>{
					if(res.code == 200){
						this.listt = res.data
						// console.log(this.listt)
						// console.log(res)
					}
					uni.hideLoading()
				})
			},
			scollSwiper(e){
			    this.current = e.target.current
				this.getGoods(this.type[e.target.current]['id'])
			},
		}
	}
</script>

<style>
	@import url("shop.css");
	@import url("../../common/uni.css");
</style>
